import 'package:flutter/material.dart';
import 'package:nfc_sbk/nfc_sbk.dart';
import '../service/nfc_reader.dart';
class NfcTest extends StatefulWidget {
  @override
  _NfcTestState createState() => _NfcTestState();
}

class _NfcTestState extends State<NfcTest> {
  String _result = "....";
  int _count=0;
  int _suCount=0;
   _readCard() async {
     NfcReader().instance.readSbk().then((result){
       setState(() {
         _result = result;
         _result ??= "not found";
         if(result!=null&&result.split(",").length==3){
         String cardId= NfcReader().instance.resolving(result.split(",")[2]);
         print("cardId:"+cardId);
         }
       });
     });
  }
_stopReadCard() async{
  NfcReader().instance.stopReadSbk();
}
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("测试"),
      ),
      body: Container(
        child: Column(
          children: <Widget>[
            RaisedButton(
              onPressed: _readCard,
              child: Text("读卡"),
            ),
            RaisedButton(
              onPressed:_stopReadCard,
              child: Text("停止读卡"),
            ),
            Text(_result),
            Text("count:$_count"),
            Text("suCount:$_suCount"),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    NfcReader().instance.stopReadSbk();
  }
}
